#include <iostream>
//产品接口
class Transport {

public:
// virtual ~Transport()= default;
 virtual void deliver() const=0;
};

class Truck:public Transport{
public:
    void deliver() const override {
        std::cout<<"卡车运输ing";
    }
};

class Ship:public Transport{
    void deliver()const override{
        std::cout<<"轮船运输ing";
    }
};
//创造者
class Logistics{
public:
    virtual Transport* factorymethod() const=0;//工厂方法
    virtual ~Logistics(){}
    void doSomething(){
        Transport * transport=factorymethod();
        transport->deliver();
        delete transport;
    }
};
//具体的创造者a
class TruckLogistis:public Logistics{
    virtual Transport* factorymethod()const {
        return new Truck;
    }
};
//具体创造者b
class ShipLogistis:public Logistics{
    virtual Transport* factorymethod()const {
        return new Ship;
    }
};
int main(){
    Logistics* trucklogistic=new TruckLogistis;//向上构造+多态
    trucklogistic->doSomething();
    Logistics* shiplogistic=new ShipLogistis;//向上构造+多态
    shiplogistic->doSomething();
    return 0;
}


